/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var meetNum = GetQueryString("meetNum");
    $("#meetNum").val(meetNum);
    var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);
    sel.addParams("meetNum", meetNum);
    getData();

    //查询
    $("#searchBtn").on("click", function () {
        var name = $("#name").val();
        var resName = $("#resName").val();
        if (name != "") {
            sel.addParams("name", name);
        } else {
            sel.addParams("name", undefined);
        }
        if (resName != "") {
            sel.addParams("resName", resName);
        } else {
            sel.addParams("resName", undefined);
        }

        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#exportDataBtn').on("click", function () {

        window.location.href = getAdminIP() + "memberMeets/exportData?meetNum=" + meetNum;
    });

    //手机号匹配事件
    $('#telBtn').on("click", function () {
        var telSel = $.Params.create();
        telSel.addParams("meetNum", meetNum);
        telSel.ajax("get", getAdminIP() + "memberMeets/updateByTel", function (data) {
            if (data.success) {
                alert(data.msg);
                getData();
            } else {
                alert(data.msg);
            }
        })
    });
    //姓名匹配
    $("#nameBtn").on("click", function () {
        sel.addParams("match", 2);
        getData();
    })

    //获取数据
    function getData() {
        getPageData("get", sel, getAdminIP() + "memberMeets", function (data) {
            if (data.success) {
                var html = "";
                if (data.total > 0) {
                    $.each(data.result, function (i, val) {
                        var isReg = "";
                        var caozuoButton = "";
                        if (val.is_register == 0) {
                            isReg = "未注册";
                            caozuoButton = "<button type='button' class='btn btn-primary'  onclick='setRegister(\"" + val.id + "\",1)'>设置已注册</button><button type='button' class='btn btn-primary'  onclick='setRegister(\"" + val.id + "\",3)'>设置不参加</button>";
                        } else if (val.is_register == 1) {
                            isReg = "已注册";
                            caozuoButton = "已注册";
                        } else {
                            isReg = "不参加";
                            caozuoButton = "不参加";
                        }
                        html += "<tr role='row'' class='even'>" +
                            "<td><input eid='" + val.id + "' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td class='sorting_1'>" + val.name + "</td>" +
                            "<td>" + val.hospital + "</td>" +
                            "<td>" + val.memName + "</td>" +
                            "<td>" + val.hospitalName + "</td>" +
                            "<td>" + val.res_name + "</td>" +
                            "<td>" + isReg + "</td>" +
                            "<td>" + val.create_time + "</td>" +
                            "<td>" + caozuoButton + "</td>" +
                            "</tr>";
                    });

                } else {
                    html = "<tr><td>暂无数据</td></tr>"
                }
                $("#listContainer").html(html);

            }
        })
    }
    setRegister = function (eid, isRegister) {
        var udtSel = $.Params.create();
        udtSel.addParams("isRegister", isRegister);
        udtSel.ajax("put", getAdminIP() + "memberMeets/" + eid, function (data) {
            if (data.success) {
                getData();
            } else {
                alert(data.msg);
            }
        })
    }
    //下载导入模板
    downloadMB = function (obj) {
        alert(getIP() + "public/data/excel/kehumoban.xlsx");
        window.location.href = getIP() + "data/excel/kehumoban.xlsx";
    }
    //点击导入按钮
    $("#uploadExcelBtn").on("click", function () {
        var exportExcel = $("#selExcel").val();
        exportExcel = exportExcel.substring(exportExcel.lastIndexOf(".") + 1);
        if (exportExcel == "xlsx") {
            $("#form_Excel").attr("action", getAdminIP() + "memberMeets/importData");
            $("#form_Excel").submit();
        } else {
            alert("请选择xlsx格式的表格");
            return false;
        }
    })

});

